package com.aw.guiguzi.module.manager._login.presenters

import com.aw.baselib.base.AwCommonPresenter
import com.aw.baselib.net.callback.AwApiCallback
import com.aw.guiguzi.bean.BasePageRspBean
import com.aw.guiguzi.bean.LoginRecordItemBean
import com.aw.guiguzi.module.manager._login.views.LoginRecordListView
import com.aw.guiguzi.net.observers.NetObCommon

/**
 * @author : hzw
 */
class LoginReordListPresent(private val mView: LoginRecordListView.View) : AwCommonPresenter(),
    LoginRecordListView.Presenter {
    override fun getLoginList(pageIndex: Int, username: String?, isLimit7Days: Boolean) {
        addIOSubscription<BasePageRspBean<LoginRecordItemBean>>(
            NetObCommon.getLoginRecordList(
                pageIndex,
                username,
                isLimit7Days
            ), object : AwApiCallback<BasePageRspBean<LoginRecordItemBean>>(mView, true, true) {
                override fun onSuccess(result: BasePageRspBean<LoginRecordItemBean>) {
                    mView.getLoginListSuccess(result.total, result?.list ?: emptyList())
                }

                override fun onFail(code: Int, msg: String) {
                    super.onFail(code, msg)
                    mView.showMsg(msg)
                    mView.getLoginListFail(code, msg)
                }
            })
    }
}